package main

import (
	"fmt"
	influx "github.com/influxdata/influxdb/client/v2"
	"time"
)

func main(){
	conf := influx.HTTPConfig{
		Addr:     "http://10.20.0.10:8086",
		Username: "root",
		Password: "123qwe",
		Timeout:  5 * time.Second,
	}
	c, err := influx.NewHTTPClient(conf)
	if err != nil{
		return
	}
	//查询所有的CQ
	query := influx.NewQuery("SHOW CONTINUOUS QUERIES", "prometheus", "ms")

	res, err := c.Query(query)
	ss := res.Results[0].Series
	for _, s := range ss{
		if s.Name == "prometheus" {
			for _, v := range s.Values{
				cq := v[0].(string)
				fmt.Println(111, cq)
				query = influx.NewQuery(fmt.Sprintf("DROP CONTINUOUS QUERY %s on prometheus", cq), "prometheus", "ms")
				res, err := c.Query(query)
				fmt.Println(res, err)
			}
		}
	}
}



